home *** CD-ROM | disk | FTP | other *** search
- Path: news.daimi.aau.dk!liborius
- From: liborius@daimi.aau.dk (Per Liboriussen)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: 3 bugs in SAS/C v. 6.56
- Date: 7 Mar 1996 14:34:18 GMT
- Organization: DAIMI, Computer Science Dept. at Aarhus University
- Message-ID: <4hms5a$35g@gjallar.daimi.aau.dk>
- References: <4gjvvc$a3t@gjallar.daimi.aau.dk> <4h6ts4$ldq@oak43.doc.ic.ac.uk>
- NNTP-Posting-Host: silene.daimi.aau.dk
- Keywords: SAS/C,bug
-
- Thus spake mdf@doc.ic.ac.uk (Martin Frost):
-
- >In article <4gjvvc$a3t@gjallar.daimi.aau.dk>, liborius@daimi.aau.dk (Per Liboriussen) writes:
- >>union un {
- >> const char *cp;
- >> char *p;
- >>};
-
- >>const char *foo(union un *unp, int n)
- > ^^^^^
- >>{
- >> return (n ? unp->p : unp->cp);
- >>}
-
- >By returning unp->p from foo(), you are returning a char * where const char *
- >is specified. The compiler should probably flag this as the error.
-
- Whereever did you get that idea from?
-
- Assigning the address of an object of type T to a pointer-to-const-T is
- always legal and safe. Such an assigment is not a guarantee that the object
- pointed to will never change, it is a promise that it will never be changed
- *through that pointer*. (Note that this has nothing to do with defining
- the object itself as const. That is indeed a guarantee that it will never
- change.)
-
- Going the other way (assigning a pointer-to-const-T to a pointer-to-T) is
- legal as well, but more dangerous, and a good compiler (such as SAS/C or GCC)
- will warn about it. But this has nothing to do with the example above.
-
-
- >Your program is not entirely correct, so you can't really complain.
-
- Yes it is, and yes I can!
-
- Besides, since when has being wrong ever prevented anyone from complaining?
- If I had a dollar for every time somebody has blamed a bug in their code
- on the compiler, I would make Bill Gates look like a poor beggar.
- (Obviously, this case is different: I _know_ that the bug is in the compiler
- and not my code ;-) ;-).)
-
-
- >Try removing the const and see if the problem goes away.
-
- The return type of foo() has nothing to do with the bug. In the original
- code where the bug was found the function corresponding to foo() didn't
- return a pointer. The only reason I wrote it that way was that I needed the
- conditional expression (as the comment you've deleted said), and I wanted
- to avoid a warning for an unused variable or a statement with no effect or
- anything like that.
-
-
- --
- Per Liboriussen
- liborius@daimi.aau.dk
-